package it.cums.core.model;

import it.cums.core.localization.Messages;

import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Date;

public class Order{
	private ArrayList<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
	private int id;
	private String status;
	private Customer customer;
	private String priority;
	private Date orderDate;
	private Date deliveryDate;
	private double totalPrice;
	private int discount;
	private double endPrice;
	private OrderedProducts orderedProducts;
	private Invoices invoices;
	
	public final static String[] STATUS = {Messages.Order_0, Messages.Order_1};
	public final static String[] PRIORITY = {Messages.Order_2, Messages.Order_3, Messages.Order_4};
	
	public Order() {
		invoices = new Invoices();
		orderedProducts = new OrderedProducts();
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getStatus() {
		return status;
	}

	public Date getOrderDate() {
		return orderDate;
	}

	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
		notifyListeners();
	}

	public void setDeliveryDate(Date deliveryDate) {
		this.deliveryDate = deliveryDate;
	}

	public Date getDeliveryDate() {
		return deliveryDate;
	}

	public void setTotalPrice(double totalPrice) {
		this.totalPrice = totalPrice;
	}

	public double getTotalPrice() {
		return totalPrice;
	}

	public void setDiscount(int discount) {
		this.discount = discount;
	}

	public int getDiscount() {
		return discount;
	}

	public void setEndPrice(double endPrice) {
		this.endPrice = endPrice;
	}

	public double getEndPrice() {
		return endPrice;
	}

	public void setOrderedProducts(OrderedProducts orderedProducts) {
		this.orderedProducts = orderedProducts;
	}

	public OrderedProducts getOrderedProducts() {
		return orderedProducts;
	}

	public void setInvoices(Invoices invoices) {
		this.invoices = invoices;
	}

	public Invoices getInvoices() {
		return invoices;
	}

	public String toString() {
		return Messages.Order_5 + id;
	}
	
	public Customer getCustomer() {
		return customer;
	}
	
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	
	public void setPriority(String priority) {
		this.priority = priority;
	}

	public String getPriority() {
		return priority;
	}

	private void notifyListeners() {
		for (PropertyChangeListener listener : listeners) {
			listener.propertyChange(null);
		}
	}
	
	public void setPropertyChangeListeners(ArrayList<PropertyChangeListener> listeners) {
		this.listeners = listeners;
	}
}
